<!DOCTYPE html>
<html>
<head>
    <title>设备详情</title>
    #parse("sys/header.html")
</head>
<body>
<div id="rrapp" v-cloak>
    <i-form ref="formValidate" :label-width="80">
        <Row>
            <i-col span="3" style="padding-right: 5px">
                <div id="qrcode" style="width: 100%;padding: 15px;"></div>
                <a :href="'../analyse/deviceMonitor.html?devCode=' + deviceInfo.devCode" target="_blank">
                    <i-button style="margin-left: 15px;" type="info">
                        查看设备监控 <Icon type="ios-arrow-forward" />
                    </i-button>
                </a>
            </i-col>
            <i-col span="7" style="padding-right: 5px">
                <Form-item label="设备名称" style= "margin-bottom: 0px">
                    {{deviceInfo.devName}}
                </Form-item>
                <Form-item label="设备厂家" style= "margin-bottom: 0px">
                    {{deviceInfo.devSupplyName}}
                </Form-item>
                <Form-item label="出厂编号" style= "margin-bottom: 0px">
                    {{deviceInfo.initCode}}
                </Form-item>
                <Form-item label="所属车间" style= "margin-bottom: 0px">
                    {{deviceInfo.devFarmName}}
                </Form-item>
                <Form-item label="产线名称" style= "margin-bottom: 0px">
                    {{deviceInfo.devProductName}}
                </Form-item>
                <Form-item label="工序名称" style="margin-bottom: 0px">
                    {{deviceInfo.devProceName}}
                </Form-item>
            </i-col>
            <i-col span="5" style="padding-right: 5px">
                <Form-item label="设备编码" style= "margin-bottom: 0px">
                    {{deviceInfo.devCode}}
                </Form-item>
                <Form-item label="底层设备码" style= "margin-bottom: 0px">
                    {{deviceInfo.devLastCode}}
                </Form-item>
                <Form-item label="设备大类" style= "margin-bottom: 0px">
                    {{deviceInfo.devTypeBName}}
                </Form-item>
                <Form-item label="设备中类" style= "margin-bottom: 0px">
                    {{deviceInfo.devTypeMName}}
                </Form-item>
                <Form-item label="设备小类" style= "margin-bottom: 0px">
                    {{deviceInfo.devTypeSName}}
                </Form-item>
                <Form-item label="固资编号" style= "margin-bottom: 0px">
                    {{deviceInfo.firmNo}}
                </Form-item>
            </i-col>
            <i-col span="4" style="padding-right: 5px">
                <Form-item label="安装日期" style= "margin-bottom: 0px">
                    {{deviceInfo.installDate}}
                </Form-item>
                <Form-item label="验收日期" style= "margin-bottom: 0px">
                    {{deviceInfo.checkDate}}
                </Form-item>
                <Form-item label="检验日期" style= "margin-bottom: 0px">
                    {{deviceInfo.nowCheckDate}}
                </Form-item>
                <Form-item label="复检周期" style= "margin-bottom: 0px">
                    {{deviceInfo.checkCycle}}
                </Form-item>
                <Form-item label="所属项目" style= "margin-bottom: 0px">
                    {{deviceInfo.devProject}}
                </Form-item>
                <Form-item label="原值" style= "margin-bottom: 0px">
                    {{deviceInfo.originVal}}
                </Form-item>
            </i-col>
            <i-col span="5" style="padding-right: 5px">
                <Form-item label="设备型号" style= "margin-bottom: 0px">
                    {{deviceInfo.reserve1}}
                </Form-item>
                <Form-item label="设备容量" style= "margin-bottom: 0px">
                    {{deviceInfo.reserve2}}
                </Form-item>
                <Form-item label="自编号" style= "margin-bottom: 0px">
                    {{deviceInfo.autoNo}}
                </Form-item>
                <Form-item label="合同编码" style= "margin-bottom: 0px">
                    {{deviceInfo.devContractCode}}
                </Form-item>
                <Form-item label="注册编号" style= "margin-bottom: 0px">
                    {{deviceInfo.regNo}}
                </Form-item>
                <Form-item label="净值" style= "margin-bottom: 0px">
                    {{deviceInfo.netWorth}}
                </Form-item>


            </i-col>
        </Row>
    </i-form>
    <Card>
        <Tabs value="name1" type="card">
            <Tab-pane label="备件包" name="name1">
                <table id="jqGrid1"></table>
            </Tab-pane>
            <Tab-pane label="维修记录" name="name2">
                <table id="jqGrid2"></table>
            </Tab-pane>
            <Tab-pane label="备件更换记录" name="name4">
                <table id="jqGrid3"></table>
            </Tab-pane>
            <Tab-pane label="知识库" name="name7">
                <table id="jqGrid6"></table>
            </Tab-pane>
            <Tab-pane label="工位" name="name11">
                <div v-show="showList">
                    <Row :gutter="16" style="margin: 3px 0px">
                        <div class="search-group">
                            <i-col span="4">
                                <i-input v-model="q.workstation" @on-enter="query" placeholder="名称"></i-input>
                            </i-col>
                            <i-button @click="query">查询</i-button>
                            <i-button @click="reloadSearch">重置</i-button>
                        </div>
                        <div class="buttons-group">
                            #if($shiro.hasPermission("devspecialworstation:save"))
                            <i-button type="info" @click="add"><i class="fa fa-plus"></i>&nbsp;新增</i-button>
                            #end
                            #if($shiro.hasPermission("devspecialworstation:update"))
                            <i-button type="warning" @click="update"><i class="fa fa-pencil-square-o"></i>&nbsp;修改</i-button>
                            #end
                            #if($shiro.hasPermission("devspecialworstation:delete"))
                            <i-button type="error" @click="del"><i class="fa fa-trash-o"></i>&nbsp;删除</i-button>
                            #end
                        </div>
                    </Row>
                    <table id="jqGrid11"></table>
                </div>
                <Card v-show="!showList">
                    <p slot="title">{{title}}</p>
                    <i-form ref="formValidate" :model="devSpecialWorstation" :rules="ruleValidate" :label-width="80">

                        <Form-item label="工位" prop="workstation">
                            <i-input v-model="devSpecialWorstation.workstation" placeholder="工位"></i-input>
                        </Form-item>
                        <Form-item>
                            <i-button type="primary" @click="handleSubmit('formValidate')">提交</i-button>
                            <i-button type="warning" @click="reload" style="margin-left: 8px">返回</i-button>
                            <i-button type="info" @click="handleReset('formValidate')" style="margin-left: 8px">重置</i-button>
                        </Form-item>
                    </i-form>
                </Card>
            </Tab-pane>
            <Tab-pane label="运行寿命记录" name="name12" v-if="deviceInfo.devKind=='2'">
                <table id="jqGrid12"></table>
            </Tab-pane>
            <Tab-pane label="固资清单" name="name13">
                <i-form ref="formValidate" :model="loadFixedAssets" :label-width="100">
                    <div v-if="loadFixedAssets.code === 500">
                        <span> {{loadFixedAssets.msg}} </span>
                    </div>
                    <div v-else >
                        <Row>
                            <i-col span="6" >
                                <Form-item label="固资编码">
                                    <span> {{loadFixedAssets.code}}</span>
                                </Form-item>
                            </i-col>
                            <i-col span="6" >
                                <Form-item label="固资名称">
                                    <span> {{loadFixedAssets.assetsName}}</span>
                                </Form-item>
                            </i-col>
                            <i-col span="6" >
                                <Form-item label="ERP资产编号">
                                    <span> {{loadFixedAssets.erpAssetsNumber}} </span>
                                </Form-item>
                            </i-col>
                            <i-col span="6" >
                                <Form-item label="资产状态">
                                    <span>{{loadFixedAssets.state}} </span>
                                </Form-item>
                            </i-col>
                        </Row>
                        <Row>
                            <i-col span="6" >
                                <Form-item label="大类">
                                    <span>{{loadFixedAssets.fcbSegment1}} </span>
                                </Form-item>
                            </i-col>
                            <i-col span="6" >
                                <Form-item label="小类">
                                    <span> {{loadFixedAssets.fcbSegment2}}</span>
                                </Form-item>
                            </i-col>
                            <i-col span="6" >
                                <Form-item label="原值">
                                    <span> {{loadFixedAssets.originVal}} </span>
                                </Form-item>
                            </i-col>
                            <i-col span="6" >
                                <Form-item label="净值">
                                    <span> {{loadFixedAssets.netWorth}} </span>
                                </Form-item>
                            </i-col>
                        </Row>
                        <Row>
                            <i-col span="6" >
                                <Form-item label="启用日期">
                                    <span>  {{loadFixedAssets.openingDate}}</span>
                                </Form-item>
                            </i-col>
                            <i-col span="6" >
                                <Form-item label="开始折旧日期">
                                    <span>{{loadFixedAssets.deprnStartDate}}</span>
                                </Form-item>
                            </i-col>
                            <i-col span="6" >
                                <Form-item label="月折旧">
                                    <span> {{loadFixedAssets.deprnAmount}}</span>
                                </Form-item>
                            </i-col>
                            <i-col span="6" >
                                <Form-item label="累计折旧">
                                    <span>{{loadFixedAssets.deprnReserve}} </span>
                                </Form-item>
                            </i-col>
                        </Row>
                        <Row>

                            <i-col span="6" >
                                <Form-item label="残值率">
                                    <span> {{loadFixedAssets.lived}}</span>
                                </Form-item>
                            </i-col>
                            <i-col span="6" >
                                <Form-item label="使用年限">
                                    <span> {{loadFixedAssets.lifeInMonths}} </span>
                                </Form-item>
                            </i-col>
                        </Row>
                    </div>

                </i-form>
            </Tab-pane>
        </Tabs>
    </Card>
</div>

<script>
    var devId = getQueryString("devId");
    var devCode = getQueryString("devCode");
    var devTypeS = getQueryString("devTypeS");
    /**
     * 备件包
     */
    $(function () {
        vm.getInfo(devId);
        vm.getFixedAssets(devId);
        $("#jqGrid1").Grid({
            url: '../sparePartKey/loadKeySparePart?devId=' + devId,
            colModel: [

                {label: '名称', name: 'name', index: 'NAME', width: 80},
                {label: '备件编码', name: 'partCode', index: 'PART_CODE', width: 80},
                {label: 'ERP编码', name: 'erpCode', index: 'ERP_CODE', width: 80},
                {label: '规格', name: 'spec', index: 'SPEC', width: 120},
                {label: '安装部位', name: 'position', index: 'POSITION', width: 80},
                {
                    label: '开始计数时间',
                    name: 'lastReplaceTime',
                    index: 'LAST_REPLACE_TIME',
                    width: 120,
                    formatter: function (value) {
                        return transDate(value, 'yyyy-MM-dd');
                    },

                },
                {label: '平均寿命', name: 'life', index: 'LIFE', width: 120},
                {label: '剩余寿命', name: 'actualLife', index: 'ACTUA_LLIFE', width: 120},

                {label: '在途数', name: 'transitNum', index: 'TRANSIT_NUM', width: 60,hidden:"true"},
                {label: '安全库存', name: 'safeNum', index: 'SAFE_NUM', width: 60,hidden:'true'},
                {label: '库存数量', name: 'stockNum', index: 'STOCK_NUM', width: 60,hidden:'true'},

            ]
        });
        vm.getworkstation();
        //二维码生成
    });
    /**
     * 维修记录
     */
    $(function () {
        $("#jqGrid2").Grid({
            url: '../devRepairRecord/list?devId=' + devId,
            autowidth: true,
            colModel: [
                {label: '产线', name: 'devProductName', index: 'DEV_PRODUCT_NAME', width: 100},
                {label: '设备编码', name: 'devCode', index: 'DEV_CODE', width: 70},
                {label: '设备名称', name: 'devName', index: 'DEV_NAME', width: 100},
                {label: '工单编号', name: 'repairCode', index: 'REPAIR_CODE', width: 90},
                {
                    label: '来源', name: 'source', index: 'SOURCE', width: 45,
                    formatter: function (value, col, row) {
                        return sysEnums.TICKET_SOURCE[value];
                    }
                },
                {label: '报修时间', name: 'uploadDate', index: 'UPLOAD_DATE', width: 90},
                {label: '维修开始时间', name: 'repairStartDate', index: 'REPAIR_START_DATE', width: 90},
                {label: '维修结束时间', name: 'repairEndDate', index: 'REPAIR_END_DATE', width: 90},
                {
                    label: '报警信息', sortable: false,
                    formatter: function (value, col, row) {
                        if (row.faultCode && row.faultDesc) {
                            return row.faultCode + '(' + row.faultDesc + ")";
                        } else {
                            return '未设置';
                        }
                    }
                },
                {label: '时长', name: 'duration', width: 40, sortable: false},
                {label: '维修人', name: 'repairUsername', index: 'REPAIR_USER', width: 40},
                {
                    label: '工单状态', width: 45, index: 'DEV_STATUS',
                    formatter: function (value, col, row) {
                        return sysEnums.REPAIR_TICKET_STATUS[row.devStatus];
                    },
                },
                {
                    label: '详情', width: 60, align: 'center', sortable: false,
                    formatter: function (value, col, row) {
                        return "<button title='详情' class='btn btn-outline btn-info'  onclick='vm.details(\"" + row.id + "\")'><i class='fa fa-file-text-o'></i></button>";
                    }
                },
                {label: '工单状态', name: 'devStatus', hidden: true},
                {label: '原维修记录ID', name: 'originRepairRecordId', hidden: true},
                {label: '设备类型', name: 'devKind', hidden: true},
                {label: '是否异常', name: 'isError', hidden: true},
                {label: '是否删除', name: 'delFlag', hidden: true},
                {label: 'id', name: 'id', index: 'ID', key: true, hidden: true}
            ],
        });
    });
    /**
     * 备件更换记录
     */
    $(function () {
        var queryUrl = '../sparepartconsumrecord/list';
        var paramArray = [];
        if (devId) {
            paramArray.push('devId=' + devId);
        }
        if (paramArray.length > 0) {
            queryUrl += '?' + paramArray.join('&');
        }
        $("#jqGrid3").Grid({
            url: queryUrl,
            colModel: [
                {
                    label: "备件类型", name: 'type', index: "TYPE", width: "90", formatter: function (value) {
                        return sysEnums.TICKET_TYPE[value];
                    }
                },
                {label: '备件编码', name: 'partCode', index: 'PART_CODE', width: 120},
                {label: '备件名称', name: 'name', index: 'NAME', width: 120},
                {label: '规格', name: 'spec', index: 'SPEC', width: 120},
                {label: '添加人', name: 'createUserName', width: 60, sortable: false, hidden: true},
                {label: '添加时间', name: 'gmtCreate', width: 60, sortable: false, hidden: true},
                {label: '领料单号', name: 'materCode', width: 60, sortable: false},
                {label: '使用数量', name: 'num', index: 'NUM', width: 60,},
                {name: 'sparePartId', hidden: true},

                {name: 'businessId', hidden: true},
                {label: 'id', name: 'id', index: 'ID', key: true, hidden: true},
            ]
        });
    });
    /**
     * 知识库
     */
    $(function () {
        $("#jqGrid6").Grid({
            url: '../knowbase/list?devCode=' + devCode,
            colModel: [
                {label: '标题', name: 'title', index: 'TITLE', width: 80},
                {label: '设备/模具编码', name: 'devCode', index: 'DEV_CODE', width: 80},
                {label: '设备/模具名称', name: 'devName', index: 'DEV_NAME', width: 80},
                {
                    label: '模块类型', name: 'type', index: 'TYPE', width: 60, formatter: function (value) {
                        return value != null ? sysEnums.KNOW_TYPE3[value] : '';
                    }
                },
                {label: '知识归类', name: 'konwTypeName', index: 'KONW_TYPE', width: 60},
                {label: '标签', name: 'keyTitile', index: 'KEY_TITILE', width: 40},
                {label: '原因', name: 'reason', index: 'REASON', width: 80},
                {label: '内容', name: 'contents', index: 'CONTENTS', width: 80},
                {label: 'id', name: 'id', index: 'ID', key: true, hidden: true},
            ]
        });
    });
    /**
     * 工位
     */
    $(function () {
        $("#jqGrid11").Grid({
            url: '../devspecialworstation/list?devId=' + devId,
            colModel: [
                {label: '工位', name: 'workstation', index: 'WORKSTATION', width: 80},
                {label: '创建人', name: 'createUserName', index: 'createUserName', width: 80},
                {
                    label: '创建时间', name: 'createTime', index: 'CREATE_TIME', width: 80, formatter: function (value) {
                        return transDate(value, "yyyy-MM-dd hh:mm");
                    }
                },
                {label: '修改人', name: 'updateUserName', index: 'updateUserName', width: 80},
                {
                    label: '修改时间', name: 'updateTime', index: 'UPDATE_TIME', width: 80, formatter: function (value) {
                        return transDate(value, "yyyy-MM-dd hh:mm");
                    }
                },
                {label: 'id', name: 'id', index: 'ID', key: true, hidden: true},
            ]
        });
    });
    /**
     * 设备运行寿命记录
     */
    $(function () {
        $("#jqGrid12").Grid({
            url: '../devicelifespanrecord/list?devId=' + devId,
            colModel: [
                {label: '当前运行寿命', name: 'currentLifeSpan', index: 'CURRENT_LIFE_SPAN', width: 80, align: 'center'},
                {label: '下次保养寿命', name: 'maintenanceLifeSpan', index: 'MAINTENANCE_LIFE_SPAN', width: 80, align: 'center'},
                {label: '录入时间', name: 'gmtCreate', index: 'GMT_CREATE', width: 80, align: 'center',formatter: function (value) {
                        return transDate(value, "yyyy-MM-dd hh:mm:ss");
                    }
                },
                {label: '录入人', name: 'createUserName', index: 'CREATE_USER', width: 80, align: 'center'},
                {name: 'id', key: true, hidden: true}
            ]
        });
    });
    function killErrors() {
        return true;
    }
    window.onerror =killErrors;
    //设备图片
    var vm = new Vue({
        el: '#rrapp',
        data: {
            q: {
                name: '',
                workstation: ''
            },
            workstation:'',
            deviceInfo: {
                devCode: '',
                devProductCode: '',
                devTypeB: '',//大类
                devTypeM: '',//中类
                devTypeS: '',//小类
                devSupply: '',//供应厂家
            },
            showList: true,
            title: null,
            loadFixedAssets:{},
            devSpecialWorstation: {},
            ruleValidate: {
                workstation: [
                    {required: true, message: '名称不能为空', trigger: 'blur'}
                ]
            }
        },
        methods: {
            details: function (id) {
                var id = id;
                if (id == null) {
                    return;
                }
                openWindow({
                    type: 2,
                    title: '<i class="fa fa-bars"></i> 维修工单详情',
                    content: '../device/devmaintenworkview.html?Id=' + id
                });
            },
            getworkstation: function () {
                Ajax.request({
                    url: '../devspecialworstation/queryAll?devId=' + devId,
                    async: true,
                    successCallback: function (r) {
                        if (r.list.length>0){
                            for(var i=0;i<r.list.length;i++){
                                vm.workstation+=(r.list[i].workstation)+','
                            }
                        }

                    }
                });
            },
            getInfo: function (id) {
                Ajax.request({
                    url: "../deviceinfo/info/" + id,
                    async: true,
                    successCallback: function (r) {
                        vm.deviceInfo = r.deviceInfo;
                    }
                });
            },
            //固资
            getFixedAssets: function (devId) {
                try {
                    Ajax.request({
                        url: "../deviceinfo/loadFixedAssets?devId=" + devId,
                        async: true,
                        successCallback: function (r) {
                            vm.loadFixedAssets = r.data;
                        },
                        failCallback: function (r) {
                            // 处理错误信息，不弹出窗口
                            console.error('请求失败:', r);
                            vm.loadFixedAssets = {
                                code: r.code,
                                msg: r.msg
                            };
                        }
                    });
                } catch (error) {
                    // 捕获异常，阻止弹窗的出现
                    console.error('请求发生异常:', error);
                }
            },
            query: function () {
                vm.reload();
            },
            add: function () {
                vm.showList = false;
                vm.title = "新增";
                vm.devSpecialWorstation = {id: '', delFlag: 1, devId: devId};
            },
            update: function (event) {
                var id = getSelectedRow("#jqGrid11");
                if (id == null) {
                    return;
                }
                vm.showList = false;
                vm.title = "修改";
                vm.getInfo2(id);
            },
            saveOrUpdate: function (event) {
                var url = vm.devSpecialWorstation.id == (null || '') ? "../devspecialworstation/save" : "../devspecialworstation/update";
                Ajax.request({
                    url: url,
                    params: JSON.stringify(vm.devSpecialWorstation),
                    type: "POST",
                    contentType: "application/json",
                    successCallback: function (r) {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
                    }
                });
            },
            del: function (event) {
                var ids = getSelectedRows("#jqGrid11");
                if (ids == null) {
                    return;
                }
                vm.getInfo2(ids);
                confirm('确定要删除选中的记录？', function () {
                    vm.devSpecialWorstation.delFlag = 0;
                    Ajax.request({
                        url: "../devspecialworstation/update",
                        params: JSON.stringify(vm.devSpecialWorstation),
                        type: "POST",
                        contentType: "application/json",
                        successCallback: function (r) {
                            alert('操作成功', function (index) {
                                vm.reload();
                            });
                        }
                    });
                });
            },
            getInfo2: function (id) {
                Ajax.request({
                    url: "../devspecialworstation/info/" + id,
                    async: true,
                    successCallback: function (r) {
                        vm.devSpecialWorstation = r.devSpecialWorstation;
                    }
                });
            },
            reload: function (event) {
                vm.showList = true;
                var page = $("#jqGrid11").jqGrid('getGridParam', 'page');
                $("#jqGrid11").jqGrid('setGridParam', {
                    postData: {'workstation': vm.q.workstation},
                    page: page
                }).trigger("reloadGrid");
                vm.handleReset('formValidate');
            },
            reloadSearch: function () {
                vm.q = {
                    workstation: ''
                };
                vm.reload();
            },
            handleSubmit: function (name) {
                handleSubmitValidate(this, name, function () {
                    vm.saveOrUpdate()
                });
            },
            handleReset: function (name) {
                handleResetForm(this, name);
            }
        }
    });
</script>
</body>
</html>
